import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    user_info: {},
    active: ''
  },
  mutations: {
    setUser(state, user) {
      state.user_info = user
    },
    addToCart(state, product) {
      state.cart.push(product)
    },
    clearCart(state) {
      state.cart = []
    },
    setActive(state, active) {
      console.log(state.user_info);
      state.active = (active == 'addcourses' || active == 'detail') ? (state.user_info.user_auth == 'student_per' ? '/home/studentcourse' : '/home/teachercourse') : (active == 'cabbage' ? state.user_info.user_auth == 'student_per' ? '/home/correct' : '/home/tcorrent' : active)
    }
  }
})

export default store